package projects;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;

public class DTNode {
	
	public DTNode() {
		children = new ArrayList<DTNode>();
		attributeValueIn = -1;
		decisionAttributeOut = -1;
		mostCommonLabel = -1;
	}
	
	public void setDepthInTree(int depth) {
		depthInTree = depth;
	}
	
	public int getTreeDepth() {
		return depthInTree;
	}
	
	public boolean hasChildren() {
		return !children.isEmpty();
	}
	
	public ArrayList<DTNode> getChildren() {
		return children;
	}
	
	public double getAttributeValueIn() {
		return attributeValueIn;
	}
	
	public DTNode childWithAttributeValueIn(double attributeValue) {
		for (DTNode child : children)
			if (child.attributeValueIn == attributeValue)
				return child;
		return null;
	}
		
	public void addChild(DTNode child) {
		children.add(child);
		child.setDepthInTree(depthInTree + 1);
	}
	
	public void setAttributeValueIn(double attribute) {
		attributeValueIn = attribute;
	}
	
	public void setDecisionAttributeOut(double attribute) {
		decisionAttributeOut = attribute;
	}
		
	public void setMostCommonLabel(double labelValue) {
		mostCommonLabel = labelValue;
	}
	
	public double getDecisionAttributeOut() {
		return decisionAttributeOut;
	}
	
	public double getMostCommonLabel() {
		return mostCommonLabel;
	}
	
	public void printNode(BufferedWriter writer) {
		try {
			writer.write("attr-val-in:" + attributeValueIn + " dec-attr-out:"  + decisionAttributeOut + "\t");
		} catch(IOException e) { e.printStackTrace(); }
	}
	
	private int depthInTree;
	private double attributeValueIn;
	private double decisionAttributeOut;
	private double mostCommonLabel;
	private ArrayList<DTNode> children;
	

}
